<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>珠峰架构师成长计划</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            珠峰架构师成长计划
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li class="active"><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-front.html">30.cms-10-front</a></li><li><a href="../html/30.cms-11-deploy.html">30.cms-11-deploy</a></li><li><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li><a href="../html/47.oauth.html">47.oauth</a></li><li><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/54.linux.html">54.linux</a></li><li><a href="../html/55.yaml.html">55.yaml</a></li><li><a href="../html/50.ketang2.html">50.ketang2</a></li><li><a href="../html/56.ts.html">56.ts</a></li><li><a href="../html/57.ts_react.html">57.ts_react</a></li><li><a href="../html/58.react-ssr.html">58.react-ssr</a></li><li><a href="../html/59.react-ssr.html">59.react-ssr</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01. 自定义可读流">1. 自定义可读流</a></li><li><a href="#t12. 可写流">2. 可写流</a></li><li><a href="#t23. 管道流">3. 管道流</a></li><li><a href="#t34. 实现双工流">4. 实现双工流</a></li><li><a href="#t45. 实现转换流">5. 实现转换流</a></li><li><a href="#t56. 对象流">6. 对象流</a></li><li><a href="#t67. unshift">7. unshift</a></li></ul>
    </div>
    
    <div class="content markdown-body">
        <h2 id="t01. &#x81EA;&#x5B9A;&#x4E49;&#x53EF;&#x8BFB;&#x6D41;">1. &#x81EA;&#x5B9A;&#x4E49;&#x53EF;&#x8BFB;&#x6D41; <a href="#t01. &#x81EA;&#x5B9A;&#x4E49;&#x53EF;&#x8BFB;&#x6D41;"> # </a></h2>
<p>&#x4E3A;&#x4E86;&#x5B9E;&#x73B0;&#x53EF;&#x8BFB;&#x6D41;&#xFF0C;&#x5F15;&#x7528;Readable&#x63A5;&#x53E3;&#x5E76;&#x7528;&#x5B83;&#x6784;&#x9020;&#x65B0;&#x5BF9;&#x8C61;</p>
<ul>
<li>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x628A;&#x4F9B;&#x4F7F;&#x7528;&#x7684;&#x6570;&#x636E;push&#x51FA;&#x53BB;&#x3002;</li>
<li>&#x5F53;push&#x4E00;&#x4E2A;null&#x5BF9;&#x8C61;&#x5C31;&#x610F;&#x5473;&#x7740;&#x6211;&#x4EEC;&#x60F3;&#x53D1;&#x51FA;&#x4FE1;&#x53F7;&#x2014;&#x2014;&#x8FD9;&#x4E2A;&#x6D41;&#x6CA1;&#x6709;&#x66F4;&#x591A;&#x6570;&#x636E;&#x4E86;&#x3002;</li>
</ul>
<pre><code>var stream = require(&apos;stream&apos;);
var util = require(&apos;util&apos;);
util.inherits(Counter, stream.Readable);
function Counter(options) {
    stream.Readable.call(this, options);
    this._index = 0;
}
Counter.prototype._read = function() {
    if(this._index++&lt;3){
        this.push(this._index+&apos;&apos;);
    }else{
        this.push(null);
    }
};
var counter = new Counter();

counter.on(&apos;data&apos;, function(data){
    console.log(&quot;&#x8BFB;&#x5230;&#x6570;&#x636E;: &quot; + data.toString());//no maybe
});
counter.on(&apos;end&apos;, function(data){
    console.log(&quot;&#x8BFB;&#x5B8C;&#x4E86;&quot;);
});

</code></pre><h2 id="t12. &#x53EF;&#x5199;&#x6D41;">2. &#x53EF;&#x5199;&#x6D41; <a href="#t12. &#x53EF;&#x5199;&#x6D41;"> # </a></h2>
<p>&#x4E3A;&#x4E86;&#x5B9E;&#x73B0;&#x53EF;&#x5199;&#x6D41;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x6D41;&#x6A21;&#x5757;&#x4E2D;&#x7684;Writable&#x6784;&#x9020;&#x51FD;&#x6570;&#x3002;
&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x7ED9;Writable&#x6784;&#x9020;&#x51FD;&#x6570;&#x4F20;&#x9012;&#x4E00;&#x4E9B;&#x9009;&#x9879;&#x5E76;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;&#x552F;&#x4E00;&#x9700;&#x8981;&#x7684;&#x9009;&#x9879;&#x662F;write&#x51FD;&#x6570;&#xFF0C;&#x8BE5;&#x51FD;&#x6570;&#x63ED;&#x9732;&#x6570;&#x636E;&#x5757;&#x8981;&#x5F80;&#x54EA;&#x91CC;&#x5199;&#x3002;</p>
<ul>
<li>chunk&#x901A;&#x5E38;&#x662F;&#x4E00;&#x4E2A;buffer&#xFF0C;&#x9664;&#x975E;&#x6211;&#x4EEC;&#x914D;&#x7F6E;&#x4E0D;&#x540C;&#x7684;&#x6D41;&#x3002;</li>
<li>encoding&#x662F;&#x5728;&#x7279;&#x5B9A;&#x60C5;&#x51B5;&#x4E0B;&#x9700;&#x8981;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x901A;&#x5E38;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5FFD;&#x7565;&#x5B83;&#x3002;</li>
<li>callback&#x662F;&#x5728;&#x5B8C;&#x6210;&#x5904;&#x7406;&#x6570;&#x636E;&#x5757;&#x540E;&#x9700;&#x8981;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x3002;&#x8FD9;&#x662F;&#x5199;&#x6570;&#x636E;&#x6210;&#x529F;&#x4E0E;&#x5426;&#x7684;&#x6807;&#x5FD7;&#x3002;&#x82E5;&#x8981;&#x53D1;&#x51FA;&#x6545;&#x969C;&#x4FE1;&#x53F7;&#xFF0C;&#x8BF7;&#x7528;&#x9519;&#x8BEF;&#x5BF9;&#x8C61;&#x8C03;&#x7528;&#x56DE;&#x8C03;&#x51FD;&#x6570;</li>
</ul>
<pre><code>var stream = require(&apos;stream&apos;);
var util = require(&apos;util&apos;);
util.inherits(Writer, stream.Writable);
let stock = [];
function Writer(opt) {
    stream.Writable.call(this, opt);
}
Writer.prototype._write = function(chunk, encoding, callback) {
    setTimeout(()=&gt;{
        stock.push(chunk.toString(&apos;utf8&apos;));
        console.log(&quot;&#x589E;&#x52A0;: &quot; + chunk);
        callback();
    },500)
};
var w = new Writer();
for (var i=1; i&lt;=5; i++){
    w.write(&quot;&#x9879;&#x76EE;:&quot; + i, &apos;utf8&apos;);
}
w.end(&quot;&#x7ED3;&#x675F;&#x5199;&#x5165;&quot;,function(){
    console.log(stock);
});
</code></pre><h2 id="t23. &#x7BA1;&#x9053;&#x6D41;">3. &#x7BA1;&#x9053;&#x6D41; <a href="#t23. &#x7BA1;&#x9053;&#x6D41;"> # </a></h2>
<pre><code>const stream = require(&apos;stream&apos;)

var index = 0;
const readable = stream.Readable({
    highWaterMark: 2,
    read: function () {
        process.nextTick(() =&gt; {
            console.log(&apos;push&apos;, ++index)
            this.push(index+&apos;&apos;);
        })
    }
})

const writable = stream.Writable({
    highWaterMark: 2,
    write: function (chunk, encoding, next) {
        console.log(&apos;&#x5199;&#x5165;:&apos;, chunk.toString())
    }
})

readable.pipe(writable);
</code></pre><h2 id="t34. &#x5B9E;&#x73B0;&#x53CC;&#x5DE5;&#x6D41;">4. &#x5B9E;&#x73B0;&#x53CC;&#x5DE5;&#x6D41; <a href="#t34. &#x5B9E;&#x73B0;&#x53CC;&#x5DE5;&#x6D41;"> # </a></h2>
<p>&#x6709;&#x4E86;&#x53CC;&#x5DE5;&#x6D41;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x540C;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x4E0A;&#x540C;&#x65F6;&#x5B9E;&#x73B0;&#x53EF;&#x8BFB;&#x548C;&#x53EF;&#x5199;&#xFF0C;&#x5C31;&#x597D;&#x50CF;&#x540C;&#x65F6;&#x7EE7;&#x627F;&#x8FD9;&#x4E24;&#x4E2A;&#x63A5;&#x53E3;&#x3002;
&#x91CD;&#x8981;&#x7684;&#x662F;&#x53CC;&#x5DE5;&#x6D41;&#x7684;&#x53EF;&#x8BFB;&#x6027;&#x548C;&#x53EF;&#x5199;&#x6027;&#x64CD;&#x4F5C;&#x5B8C;&#x5168;&#x72EC;&#x7ACB;&#x4E8E;&#x5F7C;&#x6B64;&#x3002;&#x8FD9;&#x4EC5;&#x4EC5;&#x662F;&#x5C06;&#x4E24;&#x4E2A;&#x7279;&#x6027;&#x7EC4;&#x5408;&#x6210;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code>const {Duplex} = require(&apos;stream&apos;);
const inoutStream = new Duplex({
    write(chunk, encoding, callback) {
        console.log(chunk.toString());
        callback();
    },
    read(size) {
        this.push((++this.index)+&apos;&apos;);
        if (this.index &gt; 3) {
            this.push(null);
        }
    }
});

inoutStream.index = 0;
process.stdin.pipe(inoutStream).pipe(process.stdout);
</code></pre><h2 id="t45. &#x5B9E;&#x73B0;&#x8F6C;&#x6362;&#x6D41;">5. &#x5B9E;&#x73B0;&#x8F6C;&#x6362;&#x6D41; <a href="#t45. &#x5B9E;&#x73B0;&#x8F6C;&#x6362;&#x6D41;"> # </a></h2>
<ul>
<li>&#x8F6C;&#x6362;&#x6D41;&#x7684;&#x8F93;&#x51FA;&#x662F;&#x4ECE;&#x8F93;&#x5165;&#x4E2D;&#x8BA1;&#x7B97;&#x51FA;&#x6765;&#x7684;</li>
<li>&#x5BF9;&#x4E8E;&#x8F6C;&#x6362;&#x6D41;&#xFF0C;&#x6211;&#x4EEC;&#x4E0D;&#x5FC5;&#x5B9E;&#x73B0;read&#x6216;write&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;transform&#x65B9;&#x6CD5;&#xFF0C;&#x5C06;&#x4E24;&#x8005;&#x7ED3;&#x5408;&#x8D77;&#x6765;&#x3002;&#x5B83;&#x6709;write&#x65B9;&#x6CD5;&#x7684;&#x610F;&#x601D;&#xFF0C;&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x7528;&#x5B83;&#x6765;push&#x6570;&#x636E;&#x3002;</li>
</ul>
<pre><code>const {Transform} = require(&apos;stream&apos;);

const upperCase = new Transform({
    transform(chunk, encoding, callback) {
        this.push(chunk.toString().toUpperCase());
        callback();
    }
});

process.stdin.pipe(upperCase).pipe(process.stdout);
</code></pre><h2 id="t56. &#x5BF9;&#x8C61;&#x6D41;">6. &#x5BF9;&#x8C61;&#x6D41; <a href="#t56. &#x5BF9;&#x8C61;&#x6D41;"> # </a></h2>
<p>&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x6D41;&#x5904;&#x7406;&#x7684;&#x6570;&#x636E;&#x662F;Buffer/String&#x7C7B;&#x578B;&#x7684;&#x503C;&#x3002;&#x6709;&#x4E00;&#x4E2A;objectMode&#x6807;&#x5FD7;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x5B83;&#x8BA9;&#x6D41;&#x53EF;&#x4EE5;&#x63A5;&#x53D7;&#x4EFB;&#x4F55;JavaScript&#x5BF9;&#x8C61;&#x3002;</p>
<pre><code>const {Transform} = require(&apos;stream&apos;);
let fs = require(&apos;fs&apos;);
let rs = fs.createReadStream(&apos;./users.json&apos;);
rs.setEncoding(&apos;utf8&apos;);
let toJson = Transform({
    readableObjectMode: true,
    transform(chunk, encoding, callback) {
        this.push(JSON.parse(chunk));
        callback();
    }
});
let jsonOut = Transform({
    writableObjectMode: true,
    transform(chunk, encoding, callback) {
        console.log(chunk);
        callback();
    }
});
rs.pipe(toJson).pipe(jsonOut)

</code></pre><pre><code>[
  {&quot;name&quot;:&quot;zfpx1&quot;,&quot;age&quot;:8},
  {&quot;name&quot;:&quot;zfpx2&quot;,&quot;age&quot;:9}
]
</code></pre><h2 id="t67. unshift">7. unshift <a href="#t67. unshift"> # </a></h2>
<p>readable.unshift() &#x65B9;&#x6CD5;&#x4F1A;&#x628A;&#x4E00;&#x5757;&#x6570;&#x636E;&#x538B;&#x56DE;&#x5230;Buffer&#x5185;&#x90E8;&#x3002; &#x8FD9;&#x5728;&#x5982;&#x4E0B;&#x7279;&#x5B9A;&#x60C5;&#x5F62;&#x4E0B;&#x6709;&#x7528;&#xFF1A; &#x4EE3;&#x7801;&#x6B63;&#x5728;&#x6D88;&#x8D39;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x6D41;&#xFF0C;&#x5DF2;&#x7ECF;&quot;&#x4E50;&#x89C2;&#x5730;&quot;&#x62C9;&#x53D6;&#x4E86;&#x6570;&#x636E;&#x3002; &#x53C8;&#x9700;&#x8981;&quot;&#x53CD;&#x6094;-&#x6D88;&#x8D39;&quot;&#x4E00;&#x4E9B;&#x6570;&#x636E;&#xFF0C;&#x4EE5;&#x4FBF;&#x8FD9;&#x4E9B;&#x6570;&#x636E;&#x53EF;&#x4EE5;&#x4F20;&#x7ED9;&#x5176;&#x4ED6;&#x4EBA;&#x7528;&#x3002;</p>
<pre><code>const {Transform} = require(&apos;stream&apos;);
const { StringDecoder } = require(&apos;string_decoder&apos;);
let decoder = new StringDecoder(&apos;utf8&apos;);
let fs = require(&apos;fs&apos;);
let rs = fs.createReadStream(&apos;./req.txt&apos;);

function parseHeader(stream, callback) {
    let header = &apos;&apos;;
    rs.on(&apos;readable&apos;,onReadable);
    function onReadable() {

        let chunk;
        while(null != (chunk = rs.read())){
            const str = decoder.write(chunk);
            if(str.match(/\r\n\r\n/)){
                const split = str.split(/\r\n\r\n/);
                console.log(split);
                header+=split.shift();
                const remaining = split.join(&apos;\r\n\r\n&apos;);
                const buf = Buffer.from(remaining,&apos;utf8&apos;);
                rs.removeListener(&apos;readable&apos;, onReadable);
                if(buf.length){
                    stream.unshift(buf);
                }
                callback(null,header,rs);
            }else{
                header += str;
            }
        }
    }
}
parseHeader(rs,function(err,header,stream){
    console.log(header);
    stream.setEncoding(&apos;utf8&apos;);
    stream.on(&apos;data&apos;,function (data) {
        console.log(&apos;data&apos;,data);
    });
});
</code></pre><pre><code>Host: www.baidu.com
User-Agent: curl/7.53.0
Accept: */*

name=zfpx&amp;age=9
</code></pre>
        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
